import java.io.*;
import java.util.ArrayList;

/*
 * 步骤
 * 1、读取文件，创建BufferedReader
 * 2、定义集合ArrayLiat<String>
 * 3、添加add，读取一行readLine
 * 4、将结果写到另一个文件里面，创建另外一个BufferedWriter
 * 5、倒叙遍历集合，for
 * 6、遍历集合的时候，当前字符串写到文件中：Writer
 * 7、换行：newLine
 * */
public class Example {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("example.txt"));
        ArrayList<String> list = new ArrayList<>();

        String line;
        while ((line = br.readLine()) != null) {
            list.add(line);
        }
        br.close();

        BufferedWriter bw = new BufferedWriter(new FileWriter("example1.txt"));
        for (int i = list.size()-1; i >= 0; i--) {
            bw.write(list.get(i));
            bw.newLine();
        }
        bw.close();
    }
}
